<script>
import { Table as YsTable, TableUtils } from '@/components/YS/Table'
import api from '@/api'

export default {
  name: 'AdminLogIndex',
  components: {
    YsTable
  },
  props: {
    initialFilters: {
      type: Object,
      default: null
    }
  },
  data () {
    return {
      tableConfig: {
        tableTitle: '日志列表',
        extend: {
          actions: {
            detail: () => import('@/views/admin/log/detail')
          }
        },
        // 加载数据方法 必须为 Promise 对象
        url: api.admin.log.index,
        initialFilters: this.initialFilters || {},
        rowKey: 'id',
        showRowSelection: row => { return !!row.disabled }, // 复选框 (动态渲染)
        sorter: { field: 'id', order: 'descend' },
        columns: [
          { title: this.__('ID'), dataIndex: 'id', sorter: true, ops: 'BETWEEN', width: 80 },
          { title: this.__('AdminID'), dataIndex: 'admin_id', sorter: true, ops: 'BETWEEN' },
          { title: this.__('用户名称'), dataIndex: 'username', sorter: false, ops: 'LIKE' },
          { title: this.__('URL'), dataIndex: 'url', sorter: false, ops: 'LIKE', ellipsis: true },
          { title: this.__('IP'), dataIndex: 'ip', sorter: false, ops: 'LIKE' },
          { title: this.__('标题'), dataIndex: 'title', sorter: false, ops: 'LIKE' },
          { title: this.__('UA'), dataIndex: 'useragent', sorter: false, ops: 'LIKE', ellipsis: true },
          { title: this.__('创建时间'), dataIndex: 'create_time', sorter: true, ops: 'RANGE', width: 180 },
          { title: this.__('table.operate'), ops: false, width: 70, formatter: TableUtils.formatter.operate }
        ]
      }
    }
  },
  render () {
    if (this.initialFilters === null) {
      return (<page-header-wrapper>
                <a-card bordered={false}>
                  <ys-table config={this.tableConfig}></ys-table>
                </a-card>
              </page-header-wrapper>)
    } else {
      return (<a-card bordered={false}>
                <ys-table config={this.tableConfig}></ys-table>
              </a-card>)
    }
  }
}
</script>
